import json
import requests

i = 0
headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43"
}
url = "https://blog.csdn.net/community/home-api/v1/get-business-list?page=%d8&size=20&businessType=lately&noMore=false&username=starzhou"
f = open("blog.json", "w", encoding='GBK')
active = True
def write(content):
    json.dump(content, f, indent=4, ensure_ascii=False)
    f.write("\n")
    return True
while active:
    i += 1
    res = requests.get(url % i, headers=headers)
    r = res.json()
    try:
        for j in r["data"]["list"]:
            response = {}
            response['url'] = j['url']
            response['time'] = j['formatTime']
            response['title'] = j['title']
            if j.get('description'):
                response['description'] = j['description']
            write(response)
            print(j)
    except:
        print(url % i)
        active = False
f.close()